package com.ruoyi.web.controller.basedata;

import com.ruoyi.basedata.domain.Protocol;
import com.ruoyi.basedata.service.IProtocolService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 协议Controller
 * 
 * @author ruoyi
 * @date 2023-10-08
 */
@RestController
@RequestMapping("/basedata/protocol")
public class ProtocolController extends BaseController
{
    @Autowired
    private IProtocolService protocolService;

    /**
     * 查询协议列表
     */
    @PreAuthorize("@ss.hasPermi('basedata:protocol:list')")
    @GetMapping("/list")
    public TableDataInfo list(Protocol protocol)
    {
        startPage();
        List<Protocol> list = protocolService.selectProtocolList(protocol);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasAnyPermi('basedata:protocol:list')")
    @GetMapping("/optionselect")
    public AjaxResult optionselect(Protocol protocol)
    {
        List<Protocol> list = protocolService.selectProtocolList(protocol);
        return success(list);
    }

    /**
     * 导出协议列表
     */
    @PreAuthorize("@ss.hasPermi('basedata:protocol:export')")
    @Log(title = "协议", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Protocol protocol)
    {
        List<Protocol> list = protocolService.selectProtocolList(protocol);
        ExcelUtil<Protocol> util = new ExcelUtil<Protocol>(Protocol.class);
        util.exportExcel(response, list, "协议数据");
    }

    /**
     * 获取协议详细信息
     */
    @PreAuthorize("@ss.hasPermi('basedata:protocol:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(protocolService.selectProtocolById(id));
    }

    /**
     * 新增协议
     */
    @PreAuthorize("@ss.hasPermi('basedata:protocol:add')")
    @Log(title = "协议", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Protocol protocol)
    {
        return toAjax(protocolService.insertProtocol(protocol));
    }

    /**
     * 修改协议
     */
    @PreAuthorize("@ss.hasPermi('basedata:protocol:edit')")
    @Log(title = "协议", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Protocol protocol)
    {
        return toAjax(protocolService.updateProtocol(protocol));
    }

    /**
     * 删除协议
     */
    @PreAuthorize("@ss.hasPermi('basedata:protocol:remove')")
    @Log(title = "协议", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(protocolService.deleteProtocolByIds(ids));
    }
}
